/*
 * Copyright (C) 2011-2012 Andrew Wells
 *
 * Licensed under the GNU License, Version 3
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/copyleft/gpl.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Dungeons & Dragons Copyright (C) Wizards of the Coast. I do not claim
 * the right to any information used from their books or resources.
 */

package com.trace.wells.charactertracker;

import java.io.Serializable;

public class Weapon extends Equipment implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//Is calculated based off the character's statistics: 1d20 + attackBonus
	private int attackBonus;
	private int rollBonus;
	private boolean isRanged;
	private boolean isEquipped;
	private String critical;
	private String damage;
	//The broad category of the weapon (i.e. Simple Weapon, Martion Weapon, Exotic Weapon)
	private String weaponCategory;

	//They type of weapon within each categoty (i.e. Unarmed, light melee weapon, Two-handed melee weapon)
	private String weaponStyle;

	private String range;
	private String specialAbilities;

	public Weapon(String equipmentType, String value, String name, String weight, int attackBonus, int rollBonus, boolean isRanged, boolean isEquipped, String critical, String damage, String weaponCategory,
			String weaponStyle, String range, String specialAbilities) {
		super(equipmentType, value, name, weight);
		this.attackBonus = attackBonus;
		this.rollBonus = rollBonus;
		this.isRanged = isRanged;
		this.isEquipped = isEquipped;
		this.critical = critical;
		this.damage = damage;
		this.weaponCategory = weaponCategory;
		this.weaponStyle = weaponStyle;
		this.range = range;
		this.specialAbilities = specialAbilities;
	}

	public void calculateAndSetAttackAndRollBonus(String baseAttackBonus, int strmod, int dexmod) {
		if (baseAttackBonus.contains("+")) {
			attackBonus = Integer.parseInt(baseAttackBonus.substring(1));
		}
		if (isRanged)
			this.rollBonus = dexmod;
		else
			this.rollBonus = strmod;
	}

	public String getAttackBonusString() {
		String retStr;
		if (attackBonus > -1)
			retStr = "1d20 +" + attackBonus;
		else
			retStr = "1d20 -" + attackBonus;
		return retStr;
	}

	public String getDamageBonusString() {
		String retStr;
		if (rollBonus > -1)
			retStr = damage + " +" + rollBonus;
		else
			retStr = damage + " " + rollBonus;

		return retStr;
	}

	/**
	 * @return the isRanged
	 */
	public boolean isRanged() {
		return isRanged;
	}

	/**
	 * @param isRanged
	 *            the isRanged to set
	 */
	public void setRanged(boolean isRanged) {
		this.isRanged = isRanged;
	}

	/**
	 * @return the damage
	 */
	public String getDamage() {
		return damage;
	}

	/**
	 * @param damage
	 *            the damage to set
	 */
	public void setDamage(String damage) {
		this.damage = damage;
	}

	/**
	 * @return the attackBonus
	 */
	public int getAttackBonus() {
		return attackBonus;
	}

	/**
	 * @param attackBonus
	 *            the attackBonus to set
	 */
	public void setAttackBonus(int attackBonus) {
		this.attackBonus = attackBonus;
	}

	/**
	 * @return the critical
	 */
	public String getCritical() {
		return critical;
	}

	/**
	 * @param critical
	 *            the critical to set
	 */
	public void setCritical(String critical) {
		this.critical = critical;
	}

	/**
	 * @return the range
	 */
	public String getRange() {
		return range;
	}

	/**
	 * @param range
	 *            the range to set
	 */
	public void setRange(String range) {
		this.range = range;
	}

	/**
	 * @return the specialAbilities
	 */
	public String getSpecialAbilities() {
		return specialAbilities;
	}

	/**
	 * @param specialAbilities
	 *            the specialAbilities to set
	 */
	public void setSpecialAbilities(String specialAbilities) {
		this.specialAbilities = specialAbilities;
	}

	public void setEquipped(boolean isEquipped) {
		this.isEquipped = isEquipped;
	}

	public boolean isEquipped() {
		return isEquipped;
	}

	/**
	 * @return the weaponCategory
	 */
	public String getWeaponCategory() {
		return weaponCategory;
	}

	/**
	 * @param weaponCategory
	 *            the weaponCategory to set
	 */
	public void setWeaponCategory(String weaponCategory) {
		this.weaponCategory = weaponCategory;
	}

	/**
	 * @return the weaponStyle
	 */
	public String getWeaponStyle() {
		return weaponStyle;
	}

	/**
	 * @param weaponStyle
	 *            the weaponStyle to set
	 */
	public void setWeaponStyle(String weaponStyle) {
		this.weaponStyle = weaponStyle;
	}

	public void setRollBonus(int rollBonus) {
		this.rollBonus = rollBonus;
	}

	public int getRollBonus() {
		return rollBonus;
	}
}
